import { Module } from "@nestjs/common";
import { JwtService } from "./jwt.service";
import { JwtModule as SjwtModule } from "@nestjs/jwt";
import { ConfigModule, ConfigService } from "@nestjs/config";
import { JwtStrategy } from "./jwt.strategy";
import { UserModule } from "src/user/user.module";

@Module({
    imports: [
        UserModule,
        SjwtModule.registerAsync({
            imports: [ConfigModule],
            useFactory: async (configService: ConfigService) => {
                return {
                    secret: configService.get<string>("USER_SECRET"),
                    signOptions: {
                        expiresIn: configService.get<number>("USER_TOKEN_EXPIRED"),
                    },
                };
            },
            inject: [ConfigService],
        }),
    ],
    providers: [JwtService, JwtStrategy],
    exports: [JwtService],
})
export class JwtModule {}
